
import React from 'react'

export const Option=(Data, show, Color, status)=>{
	return{
		tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        crossStyle: {
            color: '#999'
        }
      }},
    legend:{
    	orient: 'horizontal',
      x: 'left',
      left:15,
      data:Data.Title,
    },
    xAxis:[
    	{
    		type:'category',
    		data:show == 1 ? Data.name:'',
    		boundaryGap : false,
    	}],
    yAxis:[{
  		type: 'value',
  		data: show == 2 ? Data.name:'',
  		axisPointer:{
  			show:true,
  			label:{
  				formatter:"{value}"
  			}
  		}}],
    series:Series(Data,Color,show,status),
	}
}

const Series=(Data,Color,show,status)=>{
	
	const Array=[];
	if(Data.Type.indexOf("pie") < 0){
		Data.Title.forEach((now,index)=>
			Array.push({
				name:now,
				type:Data.Type[index],
				stack:'总量',
				label:{
					normal:{
						show:true,
						position:Data.Position[index]
					}
				},
				data:Data.list[index],
				itemStyle:{
					normal:{
						color:Color[index],
					}
				}
			})
		)
	}else{
		Data.Type.forEach((now,index)=>{
			Array.push({
				name: now,
				type: Data.Type[index],
				radius: Data.Radius[index],
				center: Data.center,
				label:{
					normal:{
						formatter:textHint(Data,show, status),
						rich: textRich(Data,show, status),
					}
				},
				data:textData(Data,show, status, index, Color),
			})
		})
	}
	
	return Array;
}

const Header=()=>{
	
	if(status == 1 || status == 4)
		return{
			trigger: 'axis',
      axisPointer: {
        type: 'cross',
        crossStyle: {
            color: '#999'
        }
      }
		}
	else 
		return{
			
		}
	
}

const textHint=(Data, show, status)=>{
	
	if(show == 3 && status == 1)
			return "{d}%"
}

const textRich=(Data, show, status)=>{
	if(show == 3 && status == 2)
  	return{
  		b:{
  			fontSize:14,
  			lineHeight: 33,
  		},
  		per: {
  			color:"#eee",
  			backgroundColor: "transparency",
  			padding: [2,4],
  		}
  	}	
}

const textData=(Data,show, status, index, Color)=>{

	
	if(show == 3 && status == 3)
  	 	return annulus(Data);
  	 	
  	if(show == 3 &&status == 4)
  		return Pie(Data, index, Color);
}

const annulus=(Data)=>{
	
//	const Array=[];
//	
//	Data.value.forEach((now,index)=>{
//					Array.push({
//						value:Data.value[index],
//						label: {
//							normal: {
//								formatter:'{d}%',
//								textStyle: {
//									padding:[30,0,0,0],
//									fontSize:30,
//									color:'#6D6D6D',
//								}
//							}
//						}
//					})
//	}
//	return Array;
}

const Pie=(Data, Index, Color)=>{
	
	const Array=[];

	for(let i=Index =="2" ? (Data.list[Index] -1) :0;i<Data.list[Index];i++){
						console.log(Data.name[i]);
						Array.push({
				  		value: Data.value[i],
				  		name: Data.name[i],
				  		selected: Data.active[i] ? true:null,
				  		itemStyle: {
				  			normal: {color: Color[i]}
				  		}
				  	})
						
					}
	
	console.log(Array,'数据');
	
	return Array;		  	
}
